package edu.ccut.saturn.basecomponent.baseservicecomponent;

import java.text.SimpleDateFormat;
import java.util.Date;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class GetSystemTime extends DefaultComponent {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7940670135859534406L;

	public void execute(IParameterContext parameterContext) throws Exception {
		String format = (String) parameterContext.getParameterValue(0);
		if(format == null ||"".equals(format)){
			format = "yyyy-MM-dd HH:mm:ss";
		}
		String systemTime = this.getSystemTime(format);
		parameterContext.setParameter(1, systemTime);
	}

	private String getSystemTime(String format) {
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		return simpleDateFormat.format(date);
	}
}
